package com.its.us.web.config.handler;

import com.its.us.web.utils.ConstantsUtil;
import com.its.us.web.utils.JsonUtil;
import com.its.us.web.utils.ResponseUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: master
 * @Date: 2020/11/5 15:13
 * @Version: 1.0
 */
@Component
public class MyAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        Map<String,Object> result = new HashMap<>();
        result.put("code",ConstantsUtil.HttpStatus.FORBIDDE);
        result.put("msg","没有权限");
        ResponseUtil.out(415,httpServletResponse,JsonUtil.toJson(result));
    }
}
